package com.wenjie.redHat.controller;


import com.wenjie.redHat.commom.R;
import com.wenjie.redHat.domain.entity.OrderEntity;
import com.wenjie.redHat.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping("/save")
    public R saveOrder(@RequestBody OrderEntity orderEntity){
        orderEntity.setAddtime(new Date());
       return R.success( orderService.save(orderEntity));
    }

    @ApiOperation(value = "修改订单")
    @PostMapping("/update")
    public R updaterOrder(@RequestBody OrderEntity orderEntity){
        return R.success(orderService.updateByOrder(orderEntity));
    }

    @ApiOperation(value = "查找订单")
    @GetMapping("/get/{id}")
    public R getOrder(@PathVariable Integer id){
        return R.success(orderService.getById(id));
    }

    @ApiOperation(value = "查找订单列表")
    @GetMapping("/getOrderList")
    public R getOrderList(){
        return R.success(orderService.list());
    }

    @ApiOperation(value = "删除订单")
    @PostMapping("/delect/{id}")
    public R deletedByOrder(@PathVariable Integer id){
        return R.success(orderService.removeById(id));
    }
}
